<!doctype html>
<html class="no-js" lang="">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <title>nwst-admin documentation</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="icon" type="image/x-icon" href="../images/favicon.ico">
	   <link rel="stylesheet" href="../styles/style.css">
        <link rel="stylesheet" href="../styles/dark.css" media="(prefers-color-scheme: dark)">
    </head>
    <body>

        <div class="navbar navbar-default navbar-fixed-top visible-xs">
            <a href="../" class="navbar-brand">nwst-admin documentation</a>
            <button type="button" class="btn btn-default btn-menu ion-ios-menu" id="btn-menu"></button>
        </div>

        <div class="xs-menu menu" id="mobile-menu">
                <div id="book-search-input" role="search"><input type="text" placeholder="Type to search"></div>            <compodoc-menu></compodoc-menu>
        </div>

        <div class="container-fluid main">
           <div class="row main">
               <div class="hidden-xs menu">
                   <compodoc-menu mode="normal"></compodoc-menu>
               </div>
               <!-- START CONTENT -->
               <div class="content class">
                   <div class="content-data">











<ol class="breadcrumb">
  <li>Classes</li>
  <li >ContextTrace</li>
</ol>

<ul class="nav nav-tabs" role="tablist">
        <li class="active">
            <a href="#info" role="tab" id="info-tab" data-toggle="tab" data-link="info">Info</a>
        </li>
        <li >
            <a href="#source" role="tab" id="source-tab" data-toggle="tab" data-link="source">Source</a>
        </li>
</ul>

<div class="tab-content">
    <div class="tab-pane fade active in" id="c-info">
        <p class="comment">
            <h3>File</h3>
        </p>
        <p class="comment">
            <code>src/utils/log4js.ts</code>
        </p>






            <section>
    <h3 id="index">Index</h3>
    <table class="table table-sm table-bordered index-table">
        <tbody>
                <tr>
                    <td class="col-md-4">
                        <h6><b>Properties</b></h6>
                    </td>
                </tr>
                <tr>
                    <td class="col-md-4">
                        <ul class="index-list">
                            <li>
                                    <span class="modifier">Public</span>
                                    <span class="modifier">Readonly</span>
                                    <span class="modifier">Optional</span>
                                <a href="#columnNumber" >columnNumber</a>
                            </li>
                            <li>
                                    <span class="modifier">Public</span>
                                    <span class="modifier">Readonly</span>
                                <a href="#context" >context</a>
                            </li>
                            <li>
                                    <span class="modifier">Public</span>
                                    <span class="modifier">Readonly</span>
                                    <span class="modifier">Optional</span>
                                <a href="#lineNumber" >lineNumber</a>
                            </li>
                            <li>
                                    <span class="modifier">Public</span>
                                    <span class="modifier">Readonly</span>
                                    <span class="modifier">Optional</span>
                                <a href="#path" >path</a>
                            </li>
                        </ul>
                    </td>
                </tr>






        </tbody>
    </table>
</section>

            <section>
    <h3 id="constructor">Constructor</h3>
        <table class="table table-sm table-bordered">
            <tbody>
                <tr>
                    <td class="col-md-4">
<code>constructor(context: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank">string</a>, path?: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank">string</a>, lineNumber?: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/number" target="_blank">number</a>, columnNumber?: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/number" target="_blank">number</a>)</code>
                    </td>
                </tr>
                        <tr>
                            <td class="col-md-4">
                                <div class="io-line">Defined in <a href="" data-line="23" class="link-to-prism">src/utils/log4js.ts:23</a></div>
                            </td>
                        </tr>

                <tr>
                    <td class="col-md-4">
                            <div>
                                    <b>Parameters :</b>
                                    <table class="params">
                                        <thead>
                                            <tr>
                                                <td>Name</td>
                                                    <td>Type</td>
                                                <td>Optional</td>
                                            </tr>
                                        </thead>
                                        <tbody>
                                                <tr>
                                                        <td>context</td>
                                                  
                                                        <td>
                                                                        <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>
                                                        </td>
                                                  
                                                    <td>
                                                            No
                                                    </td>
                                                    
                                                </tr>
                                                <tr>
                                                        <td>path</td>
                                                  
                                                        <td>
                                                                        <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>
                                                        </td>
                                                  
                                                    <td>
                                                            Yes
                                                    </td>
                                                    
                                                </tr>
                                                <tr>
                                                        <td>lineNumber</td>
                                                  
                                                        <td>
                                                                        <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/number" target="_blank" >number</a></code>
                                                        </td>
                                                  
                                                    <td>
                                                            Yes
                                                    </td>
                                                    
                                                </tr>
                                                <tr>
                                                        <td>columnNumber</td>
                                                  
                                                        <td>
                                                                        <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/number" target="_blank" >number</a></code>
                                                        </td>
                                                  
                                                    <td>
                                                            Yes
                                                    </td>
                                                    
                                                </tr>
                                        </tbody>
                                    </table>
                            </div>
                    </td>
                </tr>
            </tbody>
        </table>
</section>

            <section>
    
    <h3 id="inputs">
        Properties
    </h3>
    <table class="table table-sm table-bordered">
        <tbody>
            <tr>
                <td class="col-md-4">
                    <a name="columnNumber"></a>
                    <span class="name">
                            <span class="modifier">Public</span>
                            <span class="modifier">Readonly</span>
                            <span class="modifier">Optional</span>
                        <span ><b>columnNumber</b></span>
                        <a href="#columnNumber"><span class="icon ion-ios-link"></span></a>
                    </span>
                </td>
            </tr>
                <tr>
                    <td class="col-md-4">
                        <i>Type : </i>        <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/number" target="_blank" >number</a></code>

                    </td>
                </tr>
                    <tr>
                        <td class="col-md-4">
                                <div class="io-line">Defined in <a href="" data-line="28" class="link-to-prism">src/utils/log4js.ts:28</a></div>
                        </td>
                    </tr>


        </tbody>
    </table>
    <table class="table table-sm table-bordered">
        <tbody>
            <tr>
                <td class="col-md-4">
                    <a name="context"></a>
                    <span class="name">
                            <span class="modifier">Public</span>
                            <span class="modifier">Readonly</span>
                        <span ><b>context</b></span>
                        <a href="#context"><span class="icon ion-ios-link"></span></a>
                    </span>
                </td>
            </tr>
                <tr>
                    <td class="col-md-4">
                        <i>Type : </i>        <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>

                    </td>
                </tr>
                    <tr>
                        <td class="col-md-4">
                                <div class="io-line">Defined in <a href="" data-line="25" class="link-to-prism">src/utils/log4js.ts:25</a></div>
                        </td>
                    </tr>


        </tbody>
    </table>
    <table class="table table-sm table-bordered">
        <tbody>
            <tr>
                <td class="col-md-4">
                    <a name="lineNumber"></a>
                    <span class="name">
                            <span class="modifier">Public</span>
                            <span class="modifier">Readonly</span>
                            <span class="modifier">Optional</span>
                        <span ><b>lineNumber</b></span>
                        <a href="#lineNumber"><span class="icon ion-ios-link"></span></a>
                    </span>
                </td>
            </tr>
                <tr>
                    <td class="col-md-4">
                        <i>Type : </i>        <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/number" target="_blank" >number</a></code>

                    </td>
                </tr>
                    <tr>
                        <td class="col-md-4">
                                <div class="io-line">Defined in <a href="" data-line="27" class="link-to-prism">src/utils/log4js.ts:27</a></div>
                        </td>
                    </tr>


        </tbody>
    </table>
    <table class="table table-sm table-bordered">
        <tbody>
            <tr>
                <td class="col-md-4">
                    <a name="path"></a>
                    <span class="name">
                            <span class="modifier">Public</span>
                            <span class="modifier">Readonly</span>
                            <span class="modifier">Optional</span>
                        <span ><b>path</b></span>
                        <a href="#path"><span class="icon ion-ios-link"></span></a>
                    </span>
                </td>
            </tr>
                <tr>
                    <td class="col-md-4">
                        <i>Type : </i>        <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>

                    </td>
                </tr>
                    <tr>
                        <td class="col-md-4">
                                <div class="io-line">Defined in <a href="" data-line="26" class="link-to-prism">src/utils/log4js.ts:26</a></div>
                        </td>
                    </tr>


        </tbody>
    </table>
</section>







    </div>


    <div class="tab-pane fade  tab-source-code" id="c-source">
        <pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import * as Path from &#x27;path&#x27;;
import * as Log4js from &#x27;log4js&#x27;;
import * as Util from &#x27;util&#x27;;
import * as Moment from &#x27;moment&#x27;; // 处理时间的工具
import * as StackTrace from &#x27;stacktrace-js&#x27;;
import Chalk from &#x27;chalk&#x27;;
import config from &#x27;../config/log4js&#x27;;

// 日志级别
export enum LoggerLevel {
  ALL &#x3D; &#x27;ALL&#x27;,
  MARK &#x3D; &#x27;MARK&#x27;,
  TRACE &#x3D; &#x27;TRACE&#x27;,
  DEBUG &#x3D; &#x27;DEBUG&#x27;,
  INFO &#x3D; &#x27;INFO&#x27;,
  WARN &#x3D; &#x27;WARN&#x27;,
  ERROR &#x3D; &#x27;ERROR&#x27;,
  FATAL &#x3D; &#x27;FATAL&#x27;,
  OFF &#x3D; &#x27;OFF&#x27;,
}

// 内容跟踪类
export class ContextTrace {
  constructor(
    public readonly context: string,
    public readonly path?: string,
    public readonly lineNumber?: number,
    public readonly columnNumber?: number,
  ) {}
}

Log4js.addLayout(&#x27;Awesome-nest&#x27;, (logConfig: any) &#x3D;&gt; {
  return (logEvent: Log4js.LoggingEvent): string &#x3D;&gt; {
    let moduleName &#x3D; &#x27;&#x27;;
    let position &#x3D; &#x27;&#x27;;

    // 日志组装
    const messageList: string[] &#x3D; [];
    logEvent.data.forEach((value: any) &#x3D;&gt; {
      if (value instanceof ContextTrace) {
        moduleName &#x3D; value.context;
        // 显示触发日志的坐标（行，列）
        if (value.lineNumber &amp;&amp; value.columnNumber) {
          position &#x3D; &#x60;${value.lineNumber}, ${value.columnNumber}&#x60;;
        }
        return;
      }

      if (typeof value !&#x3D;&#x3D; &#x27;string&#x27;) {
        value &#x3D; Util.inspect(value, false, 3, true);
      }

      messageList.push(value);
    });

    // 日志组成部分
    const messageOutput: string &#x3D; messageList.join(&#x27; &#x27;);
    const positionOutput: string &#x3D; position ? &#x60; [${position}]&#x60; : &#x27;&#x27;;
    const typeOutput &#x3D; &#x60;[${logConfig.type}] ${logEvent.pid.toString()}   - &#x60;;
    const dateOutput &#x3D; &#x60;${Moment(logEvent.startTime).format(
      &#x27;YYYY-MM-DD HH:mm:ss&#x27;,
    )}&#x60;;
    const moduleOutput: string &#x3D; moduleName
      ? &#x60;[${moduleName}] &#x60;
      : &#x27;[LoggerService] &#x27;;
    let levelOutput &#x3D; &#x60;[${logEvent.level}] ${messageOutput}&#x60;;

    // 根据日志级别，用不同颜色区分
    switch (logEvent.level.toString()) {
      case LoggerLevel.DEBUG:
        levelOutput &#x3D; Chalk.green(levelOutput);
        break;
      case LoggerLevel.INFO:
        levelOutput &#x3D; Chalk.cyan(levelOutput);
        break;
      case LoggerLevel.WARN:
        levelOutput &#x3D; Chalk.yellow(levelOutput);
        break;
      case LoggerLevel.ERROR:
        levelOutput &#x3D; Chalk.red(levelOutput);
        break;
      case LoggerLevel.FATAL:
        levelOutput &#x3D; Chalk.hex(&#x27;#DD4C35&#x27;)(levelOutput);
        break;
      default:
        levelOutput &#x3D; Chalk.grey(levelOutput);
        break;
    }

    return &#x60;${Chalk.green(typeOutput)}${dateOutput}  ${Chalk.yellow(
      moduleOutput,
    )}${levelOutput}${positionOutput}&#x60;;
  };
});

// 注入配置
Log4js.configure(config);

// 实例化
const logger &#x3D; Log4js.getLogger();
logger.level &#x3D; LoggerLevel.TRACE;

export class Logger {
  static trace(...args) {
    logger.trace(Logger.getStackTrace(), ...args);
  }

  static debug(...args) {
    logger.debug(Logger.getStackTrace(), ...args);
  }

  static log(...args) {
    logger.info(Logger.getStackTrace(), ...args);
  }

  static info(...args) {
    logger.info(Logger.getStackTrace(), ...args);
  }

  static warn(...args) {
    logger.warn(Logger.getStackTrace(), ...args);
  }

  static warning(...args) {
    logger.warn(Logger.getStackTrace(), ...args);
  }

  static error(...args) {
    logger.error(Logger.getStackTrace(), ...args);
  }

  static fatal(...args) {
    logger.fatal(Logger.getStackTrace(), ...args);
  }

  static access(...args) {
    const loggerCustom &#x3D; Log4js.getLogger(&#x27;http&#x27;);
    loggerCustom.info(Logger.getStackTrace(), ...args);
  }

  // 日志追踪，可以追溯到哪个文件、第几行第几列
  static getStackTrace(deep &#x3D; 2): string {
    const stackList: StackTrace.StackFrame[] &#x3D; StackTrace.getSync();
    const stackInfo: StackTrace.StackFrame &#x3D; stackList[deep];

    const lineNumber: number &#x3D; stackInfo.lineNumber;
    const columnNumber: number &#x3D; stackInfo.columnNumber;
    const fileName: string &#x3D; stackInfo.fileName;
    const basename: string &#x3D; Path.basename(fileName);
    return &#x60;${basename}(line: ${lineNumber}, column: ${columnNumber}): \n&#x60;;
  }
}
</code></pre>
    </div>
</div>








                   </div><div class="search-results">
    <div class="has-results">
        <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
        <ul class="search-results-list"></ul>
    </div>
    <div class="no-results">
        <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
    </div>
</div>
</div>
               <!-- END CONTENT -->
           </div>
       </div>

       <script>
            var COMPODOC_CURRENT_PAGE_DEPTH = 1;
            var COMPODOC_CURRENT_PAGE_CONTEXT = 'class';
            var COMPODOC_CURRENT_PAGE_URL = 'ContextTrace.html';
            var MAX_SEARCH_RESULTS = 15;
       </script>

       <script src="../js/libs/custom-elements.min.js"></script>
       <script src="../js/libs/lit-html.js"></script>

       <script src="../js/menu-wc.js" defer></script>
       <script nomodule src="../js/menu-wc_es5.js" defer></script>

       <script src="../js/libs/bootstrap-native.js"></script>

       <script src="../js/libs/es6-shim.min.js"></script>
       <script src="../js/libs/EventDispatcher.js"></script>
       <script src="../js/libs/promise.min.js"></script>
       <script src="../js/libs/zepto.min.js"></script>

       <script src="../js/compodoc.js"></script>

       <script src="../js/tabs.js"></script>
       <script src="../js/menu.js"></script>
       <script src="../js/libs/clipboard.min.js"></script>
       <script src="../js/libs/prism.js"></script>
       <script src="../js/sourceCode.js"></script>
          <script src="../js/search/search.js"></script>
          <script src="../js/search/lunr.min.js"></script>
          <script src="../js/search/search-lunr.js"></script>
          <script src="../js/search/search_index.js"></script>
       <script src="../js/lazy-load-graphs.js"></script>


    </body>
</html>
